<?php

namespace IDock\Insurance\LIHI\Request;

use IDock\Insurance\LIHI\Response\NonCarInquiryResponse;
use IDock\Visitor\NonCar\NonCarProductVisitor;
use IDock\Visitor\Premium\PremiumInquiryVisitor;

class NonCarInquiryRequest extends AllLIHIRequest
{

    protected $urlTip = '非车计划保存';

    public $route = 'cpservice/savePlan';

    protected $response = NonCarInquiryResponse::class;

    /*** @var  PremiumInquiryVisitor $visitor */
    protected $visitor;

    public $proposalNo = '';

    public $agreementCode;

    public function generate(): array
    {
        $this->agreementCode = $this->visitor->getExtInfoVisitor()->argc['agreementNo'] ?? '';
        $this->recordCode = $this->visitor->getExtInfoVisitor()->argc['recordCode'] ?? '';

        $this->flowId = $this->visitor->getExtInfoVisitor()->argc['flowId'] ?? '';
        /**
         * @var NonCarProductVisitor $row
         */
        $row = $this->visitor->getNonCarInquiryVisitor()->getNonCarList()[0] ?? [];

        $planList = json_decode($row->argc['planJson'] ?? [], true);

        $planList['agreementCode'] = $this->agreementCode;

        return [
            'planLists' => [
                $planList
            ],
        ];
    }
}
